﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lswweb.IDAL;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Domain
{
    public class GuestBook
    {
        private static IGuestBook guestBookDAL = DALFactory.CreateGuestBook();

        public static GuestbookInfo GetGuestBook(int id)
        {
            return guestBookDAL.GetGuestBook(id);
        }

        public static void Insert(GuestbookInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            if (guestBookDAL.Insert(info) > 0)
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            else
                SiteContext.RenderMessage(ExceptionType.UnknownError);
        }

        public static void Delete(int id)
        {
            if (id <= 0)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            if (guestBookDAL.Delete(id))
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            else
                SiteContext.RenderMessage(ExceptionType.UnknownError);
        }

        public static void IsRead()
        {
            guestBookDAL.UpdateIsRead(SiteContext.Current.Id);
        }

        public static IList<GuestbookInfo> GetGuestBooks(bool? isRead, GuestBookItem? itemType, int pageSize, int pageIndex, out int totalRecord)
        {
            return guestBookDAL.GetGuestBooks(isRead, itemType, pageSize, pageIndex, out totalRecord);
        }
    }
}
